<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="什么是软中断？若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV06-13-中断-03-软中断">
<meta property="og:url" content="https://sumumm.github.io/post/22e3d685.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="什么是软中断？若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323112748234.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250215092439483.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250318155714988.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/1.iodraw.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323110944722.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323113247086.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323114255189.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323114328644.png">
<meta property="article:published_time" content="2025-03-23T10:40:39.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.057Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV06-驱动开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323112748234.png">


<link rel="canonical" href="https://sumumm.github.io/post/22e3d685.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":"","permalink":"https://sumumm.github.io/post/22e3d685.html","path":"post/22e3d685.html","title":"LV06-13-中断-03-软中断"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV06-13-中断-03-软中断 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E8%BD%AF%E4%B8%AD%E6%96%AD%E8%AF%B7%E6%B1%82-softirq-%E7%AE%80%E4%BB%8B"><span class="nav-text">一、软中断请求(softirq)简介</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BB%80%E4%B9%88%E6%98%AF%E8%BD%AF%E4%B8%AD%E6%96%AD"><span class="nav-text">1. 什么是软中断</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%BD%AF%E4%B8%AD%E6%96%AD%E8%AF%B7%E6%B1%82%E6%8F%8F%E8%BF%B0%E7%AC%A6"><span class="nav-text">2. 软中断请求描述符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%9C%A8linux%E4%B8%AD%E7%9A%84%E8%A1%A8%E7%8E%B0"><span class="nav-text">3. 在linux中的表现</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E8%BD%AF%E4%B8%AD%E6%96%AD%E7%9B%B8%E5%85%B3%E6%93%8D%E4%BD%9C"><span class="nav-text">二、软中断相关操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%AD%E6%96%AD%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0%EF%BC%9F"><span class="nav-text">1. 中断处理函数？</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E6%B3%A8%E5%86%8C%E4%B8%80%E4%B8%AA%E4%B8%AD%E6%96%AD%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0"><span class="nav-text">1.1 注册一个中断处理函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E6%B3%A8%E5%86%8C%E7%9A%84%E5%87%BD%E6%95%B0%E6%80%8E%E4%B9%88%E6%89%A7%E8%A1%8C%EF%BC%9F"><span class="nav-text">1.2 注册的函数怎么执行？</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%BD%AF%E4%B8%AD%E6%96%AD%E8%A7%A6%E5%8F%91%E6%9C%BA%E5%88%B6"><span class="nav-text">2. 软中断触发机制</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E8%BD%AF%E4%B8%AD%E6%96%AD%E7%9A%84%E4%BD%8D%E5%9B%BE"><span class="nav-text">2.1 软中断的位图</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-1-%E6%80%8E%E4%B9%88%E7%A1%AE%E5%AE%9A%E6%98%AF%E5%93%AA%E4%B8%AACPU%E7%9A%84%EF%BC%9F"><span class="nav-text">2.1.1 怎么确定是哪个CPU的？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-2-%E8%BD%AF%E4%B8%AD%E6%96%AD%E4%BD%8D%E5%9B%BE"><span class="nav-text">2.1.2 软中断位图</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E8%BD%AF%E4%B8%AD%E6%96%AD%E8%A7%A6%E5%8F%91%E5%87%BD%E6%95%B0"><span class="nav-text">2.2 软中断触发函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E8%BD%AF%E4%B8%AD%E6%96%AD%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="nav-text">3. 软中断的初始化</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E4%B8%AD%E6%96%AD%E7%9A%84%E4%B8%8B%E5%8D%8A%E9%83%A8"><span class="nav-text">三、中断的下半部</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%BD%AF%E4%B8%AD%E6%96%AD%E6%80%8E%E4%B9%88%E5%AE%8C%E6%88%90%E4%B8%AD%E6%96%AD%E4%B8%8B%E5%8D%8A%E9%83%A8%EF%BC%9F"><span class="nav-text">1. 软中断怎么完成中断下半部？</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E8%BD%AF%E4%B8%AD%E6%96%ADdemo"><span class="nav-text">四、软中断demo</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-demo%E6%BA%90%E7%A0%81"><span class="nav-text">1. demo源码</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-linux%E5%86%85%E6%A0%B8%E6%BA%90%E7%A0%81%E4%BF%AE%E6%94%B9"><span class="nav-text">1.1 linux内核源码修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E9%A9%B1%E5%8A%A8%E6%BA%90%E7%A0%81"><span class="nav-text">1.2 驱动源码</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%BC%80%E5%8F%91%E6%9D%BF%E6%B5%8B%E8%AF%95"><span class="nav-text">2. 开发板测试</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/22e3d685.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV06-13-中断-03-软中断 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV06-13-中断-03-软中断
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2025-03-23 18:40:39" itemprop="dateCreated datePublished" datetime="2025-03-23T18:40:39+08:00">2025-03-23</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/" itemprop="url" rel="index"><span itemprop="name">02IMX6ULL平台</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV06-驱动开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>16 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>什么是软中断？若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" rowspan="5">PC端开发环境</td>        <td align="center" width=150px>Windows</td>        <td align="left">Windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu20.04.2的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 17 Pro</td>        <td align="left">17.6.0 build-24238078</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>    </tr>    <tr>        <td align="center">Win32DiskImager</td>        <td align="left">Win32DiskImager v1.0</td>      </tr>    <tr>        <td align="center" rowspan="3">Linux开发板环境</td>        <td align="center">Linux开发板</td>        <td align="left">正点原子 i.MX6ULL Linux 阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，使用的uboot版本为U-Boot 2019.04</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.19.71(NXP官方提供)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="5">官方网站</td>        <td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td>        <td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/" target="_blank">https://www.nxp.com.cn/ </a></td>        <td align="left">NXP官方网站</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxpic.org.cn/" target="_blank">https://www.nxpic.org.cn/</a></td><td align="left">NXP 官方社区</td>    </tr>    <tr>        <td align="left"><a href="https://u-boot.readthedocs.io/en/latest/" target="_blank">https://u-boot.readthedocs.io/en/latest/</a></td><td align="left">u-boot官网</td>    </tr>    <tr>        <td align="left"><a href="https://www.kernel.org/" target="_blank">https://www.kernel.org/</a></td><td align="left">linux内核官网</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="3">NXP</td>        <td align="left"><a href="https://github.com/nxp-imx" target="_blank">https://github.com/nxp-imx</a></td>        <td align="left">NXP imx开发资源GitHub组织，里边会有u-boot和linux内核的仓库</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/linux-imx/releases/tag/v4.19.71" target="_blank">nxp-imx/linux-imx/releases/tag/v4.19.71</a></td>        <td align="left">NXP linux内核仓库tags中的v4.19.71</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/uboot-imx/releases/tag/rel_imx_4.19.35_1.1.0" target="_blank">nxp-imx/uboot-imx/releases/tag/rel_imx_4.19.35_1.1.0</a></td>        <td align="left">NXP u-boot仓库tags中的rel_imx_4.19.35_1.1.0</td>    </tr>    <tr>        <td align="center" rowspan="2">I.MX6ULL</td>        <td align="left"><a href="https://www.nxp.com.cn/docs/en/data-sheet/IMX6ULLIEC.pdf" target="_blank">i.MX 6ULL Applications Processors for Industrial Products</a></td>        <td align="left">I.MX6ULL 芯片手册（datasheet，可以在线查看）</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/webapp/Download?colCode=IMX6ULLRM&lang_cd=zh" target="_blank">i.MX 6ULL Applications ProcessorReference Manual</a></td>        <td align="left">I.MX6ULL 参考手册（下载后才能查看，需要登录NXP官网）</td>    </tr>    <tr>        <td align="center" rowspan="3">Source Code</td>        <td align="left"><a href="https://elixir.bootlin.com/linux/latest/source" target="_blank">https://elixir.bootlin.com/linux/latest/source</a></td>        <td align="left">linux kernel源码</td>    </tr>    <tr>        <td align="left"><a href="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/?h=v4.19.71&id=e7d2672c66e4d3675570369bf20856296da312c4" target="_blank">kernel/git/stable/linux.git - Linux kernel stable tree</a></td>        <td align="left">linux kernel源码(官网,tag 4.19.71)</td>    </tr>    <tr>        <td align="left"><a href="https://elixir.bootlin.com/u-boot/latest/source" target="_blank">https://elixir.bootlin.com/u-boot/latest/source</a></td>        <td align="left">uboot源码</td>    </tr></table>
              </div>
            </details>

<h1 id="一、软中断请求-softirq-简介"><a href="#一、软中断请求-softirq-简介" class="headerlink" title="一、软中断请求(softirq)简介"></a><font size=3>一、软中断请求(softirq)简介</font></h1><h2 id="1-什么是软中断"><a href="#1-什么是软中断" class="headerlink" title="1. 什么是软中断"></a><font size=3>1. 什么是软中断</font></h2><p>Linux的softirq机制是与SMP紧密不可分的。为此，整个softirq机制的设计与实现中自始自终都贯彻了一个思想：“谁触发，谁执行”（Who marks，Who runs），也即触发软中断的那个CPU负责执行它所触发的软中断，而且每个CPU都有它自己的软中断触发与控制机制。这个设计思想也使得softirq机制充分利用了SMP系统的性能和特点。</p>
<h2 id="2-软中断请求描述符"><a href="#2-软中断请求描述符" class="headerlink" title="2. 软中断请求描述符"></a><font size=3>2. 软中断请求描述符</font></h2><p>Linux在<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/include/linux/interrupt.h">interrupt.h - include&#x2F;linux&#x2F;interrupt.h</a>头文件中定义了数据结构 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/include/linux/interrupt.h#L491">softirq_action</a> ，来描述一个软中断请求，如下所示：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">softirq_action</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">	<span class="type">void</span>	(*action)(<span class="keyword">struct</span> softirq_action *);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>Linux在<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L56">softirq.c - kernel&#x2F;softirq.c</a>文件中定义了一个全局的<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L56">softirq_vec</a>数组：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="class"><span class="keyword">struct</span> <span class="title">softirq_action</span> <span class="title">softirq_vec</span>[<span class="title">NR_SOFTIRQS</span>] __<span class="title">cacheline_aligned_in_smp</span>;</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/include/linux/interrupt.h#L477">NR_SOFTIRQS</a>是枚举类型：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">enum</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">	HI_SOFTIRQ=<span class="number">0</span>,  <span class="comment">// 高优先级软中断</span></span><br><span class="line">	TIMER_SOFTIRQ, <span class="comment">// 定时器软中断</span></span><br><span class="line">	NET_TX_SOFTIRQ,<span class="comment">// 网络传输发送软中断</span></span><br><span class="line">	NET_RX_SOFTIRQ,<span class="comment">// 网络传输接收软中断</span></span><br><span class="line">	BLOCK_SOFTIRQ, <span class="comment">// 块设备软中断</span></span><br><span class="line">	IRQ_POLL_SOFTIRQ,<span class="comment">// 中断轮询软中断</span></span><br><span class="line">	TASKLET_SOFTIRQ, <span class="comment">// 任务软中断</span></span><br><span class="line">	SCHED_SOFTIRQ,   <span class="comment">// 调度软中断</span></span><br><span class="line">	HRTIMER_SOFTIRQ, <span class="comment">/* Unused, but kept as tools rely on the numbering. Sigh! */</span></span><br><span class="line">	RCU_SOFTIRQ,    <span class="comment">/* Preferable RCU should always be the last softirq */</span></span><br><span class="line"></span><br><span class="line">	NR_SOFTIRQS      <span class="comment">// 表示软中断的总数， 用于指示软中断类型的数据</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>在这里系统一共定义了10个软中断请求描述符，中断号的优先级越小， 代表优先级越高。 在驱动代码中， 我们可以使用 Linux 驱动代码中上述的软中断， 当然我们也可以自己添加软中断。软中断向量i（0≤i≤9）所对应的软中断请求描述符就是softirq_vec[i]。这个数组是个系统全局数组，即它被所有的CPU（对于SMP系统而言）所共享。这里需要注意的一点是：每个CPU虽然都有它自己的触发和控制机制，并且只执行自己所触发的软中断请求，但是各个CPU所执行的软中断服务函数却是相同的，也即都是执行softirq_vec[ ]数组中定义的 action 软中断服务函数。</p>
<h2 id="3-在linux中的表现"><a href="#3-在linux中的表现" class="headerlink" title="3. 在linux中的表现"></a><font size=3>3. 在linux中的表现</font></h2><p>我们可以用以下命令查看一下现在系统中支持哪些软中断：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /proc/softirqs</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323112748234.png" alt="image-20250323112748234" />

<h1 id="二、软中断相关操作"><a href="#二、软中断相关操作" class="headerlink" title="二、软中断相关操作"></a><font size=3>二、软中断相关操作</font></h1><h2 id="1-中断处理函数？"><a href="#1-中断处理函数？" class="headerlink" title="1. 中断处理函数？"></a><font size=3>1. 中断处理函数？</font></h2><h3 id="1-1-注册一个中断处理函数"><a href="#1-1-注册一个中断处理函数" class="headerlink" title="1.1 注册一个中断处理函数"></a><font size=3>1.1 注册一个中断处理函数</font></h3><p>要使用软中断，必须先使用 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L454">open_softirq()</a> 函数注册对应的软中断处理函数，<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L454">open_softirq()</a>函数原型如下：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">open_softirq</span><span class="params">(<span class="type">int</span> nr, <span class="type">void</span> (*action)(<span class="keyword">struct</span> softirq_action *))</span></span><br><span class="line">&#123;</span><br><span class="line">	softirq_vec[nr].action = action;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>向内核注册一个软中断，其实质是设置软中断向量表相应槽位。</p>
<p><strong>参数说明：</strong></p>
<ul>
<li><p>nr：要开启的软中断。</p>
</li>
<li><p>action：软中断对应的处理函数。</p>
</li>
</ul>
<p><strong>返回值：</strong>无</p>
<h3 id="1-2-注册的函数怎么执行？"><a href="#1-2-注册的函数怎么执行？" class="headerlink" title="1.2 注册的函数怎么执行？"></a><font size=3>1.2 注册的函数怎么执行？</font></h3><p>软中断的核心处理函数是<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L323">do_softirq()</a>，它处理当前CPU上的所有软中断。中间好复杂，暂时没有详细去研究了，在arm平台，最终好像调用到 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L249">__do_softirq()</a> </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">asmlinkage __visible <span class="type">void</span> __softirq_entry __do_softirq(<span class="type">void</span>)</span><br><span class="line">&#123;</span><br><span class="line">	<span class="comment">//......</span></span><br><span class="line">	h = softirq_vec; <span class="comment">// 取得软中断向量 </span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">while</span> ((softirq_bit = ffs(pending))) &#123;</span><br><span class="line">		<span class="comment">//......</span></span><br><span class="line">		h-&gt;action(h); <span class="comment">// 调用软中断</span></span><br><span class="line">		<span class="comment">//......</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">//......</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="2-软中断触发机制"><a href="#2-软中断触发机制" class="headerlink" title="2. 软中断触发机制"></a><font size=3>2. 软中断触发机制</font></h2><h3 id="2-1-软中断的位图"><a href="#2-1-软中断的位图" class="headerlink" title="2.1 软中断的位图"></a><font size=3>2.1 软中断的位图</font></h3><p>要实现“谁触发，谁执行”的思想，就必须为每个CPU都定义它自己的触发和控制变量。为此，Linux定义了一个<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/arch/arm/include/asm/hardirq.h#L17">irq_cpustat_t</a> 数据结构来描述一个CPU的中断信息，这个在多个头文件中都有定义：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250215092439483.png" alt="image-20250215092439483"  />

<p>这里以 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/arch/arm/include/asm/hardirq.h#L17">hardirq.h - arch&#x2F;arm&#x2F;include&#x2F;asm&#x2F;hardirq.h</a> 为例：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* number of IPIS _not_ including IPI_CPU_BACKTRACE */</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> NR_IPI	7</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> &#123;</span></span><br><span class="line">	<span class="type">unsigned</span> <span class="type">int</span> __softirq_pending;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> CONFIG_SMP</span></span><br><span class="line">	<span class="type">unsigned</span> <span class="type">int</span> ipi_irqs[NR_IPI];</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">&#125; ____cacheline_aligned <span class="type">irq_cpustat_t</span>;</span><br></pre></td></tr></table></figure>

<p>内核中使用这个数据结构定义了一个全局变量 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/include/linux/irq_cpustat.h#L21">irq_stat</a>：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifndef</span> __ARCH_IRQ_STAT</span></span><br><span class="line">DECLARE_PER_CPU_ALIGNED(<span class="type">irq_cpustat_t</span>, irq_stat);	<span class="comment">/* defined in asm/hardirq.h */</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> __IRQ_STAT(cpu, member)	(per_cpu(irq_stat.member, cpu))</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>

<p>irq_stat的定义我们可以展开看一下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> DECLARE_PER_CPU_ALIGNED(type, name)				\</span></span><br><span class="line"><span class="meta">	DECLARE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION)	\</span></span><br><span class="line"><span class="meta">	____cacheline_aligned</span></span><br></pre></td></tr></table></figure>

<p>这里牵扯的宏有点多，我就没深挖了，大概是这样的一个变量：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">irq_cpustat_t</span> irq_stat[NR_CPUS] __cacheline_aligned;</span><br></pre></td></tr></table></figure>

<p>NR_CPUS为系统中CPU个数，这样，每个CPU都只操作它自己的中断统计信息结构。假设有一个编号为id的CPU，那么它只能操作它自己的中断统计信息结构 irq_stat［id］（0≤id≤NR_CPUS-1），从而使各CPU之间互不影响。</p>
<h4 id="2-1-1-怎么确定是哪个CPU的？"><a href="#2-1-1-怎么确定是哪个CPU的？" class="headerlink" title="2.1.1 怎么确定是哪个CPU的？"></a><font size=3>2.1.1 怎么确定是哪个CPU的？</font></h4><p><a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/arch/arm/include/asm/hardirq.h#L17">irq_cpustat_t</a>中的 IPI 表示处理器间的中断(Inter-Processor Interrupts):</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> NR_IPI	7</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> &#123;</span></span><br><span class="line">	<span class="type">unsigned</span> <span class="type">int</span> __softirq_pending;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> CONFIG_SMP</span></span><br><span class="line">	<span class="type">unsigned</span> <span class="type">int</span> ipi_irqs[NR_IPI];</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">&#125; ____cacheline_aligned <span class="type">irq_cpustat_t</span>;</span><br></pre></td></tr></table></figure>

<h4 id="2-1-2-软中断位图"><a href="#2-1-2-软中断位图" class="headerlink" title="2.1.2 软中断位图"></a><font size=3>2.1.2 软中断位图</font></h4><p>内核使用一个名为 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/arch/arm/include/asm/hardirq.h#L17">irq_cpustat_t</a>.<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/arch/arm/include/asm/hardirq.h#L13">__softirq_pending</a> 的位图来描述软中断，<strong>每一个位对应一个软中断</strong>。内核提供了一些宏来对这个位图进行操作。</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/include/linux/interrupt.h#L443">or_softirq_pending()</a>用于设置相应的位（位或操作），<a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/include/linux/interrupt.h#L441">local_softirq_pending()</a>用于取得整个位图</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifndef</span> local_softirq_pending_ref</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> local_softirq_pending_ref irq_stat.__softirq_pending</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> local_softirq_pending()	(__this_cpu_read(local_softirq_pending_ref))</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> set_softirq_pending(x)	(__this_cpu_write(local_softirq_pending_ref, (x)))</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> or_softirq_pending(x)	(__this_cpu_or(local_softirq_pending_ref, (x)))</span></span><br></pre></td></tr></table></figure>

<ul>
<li><a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L448">__raise_softirq_irqoff()</a>用于实现激活软中断。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> __raise_softirq_irqoff(<span class="type">unsigned</span> <span class="type">int</span> nr)</span><br><span class="line">&#123;</span><br><span class="line">	trace_softirq_raise(nr);</span><br><span class="line">	or_softirq_pending(<span class="number">1UL</span> &lt;&lt; nr);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-软中断触发函数"><a href="#2-2-软中断触发函数" class="headerlink" title="2.2 软中断触发函数"></a><font size=3>2.2 软中断触发函数</font></h3><p>触发软中断的函数为 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L439">raise_softirq()</a> </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">void raise_softirq(unsigned int nr)</span><br><span class="line">&#123;</span><br><span class="line">	unsigned long flags;</span><br><span class="line"></span><br><span class="line">	local_irq_save(flags);</span><br><span class="line">	raise_softirq_irqoff(nr);</span><br><span class="line">	local_irq_restore(flags);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>raise_softirq()函数激活软中断，参数nr为要触发的软中断。这里使用术语“激活”而非“调用”， 是因为在很多情况下不能直接调用软中断。所以只能快速地将其标志为“可执行”，等待未来某一时刻调用。</p>
<blockquote>
<p>Tips：为什么“在很多情况下不能直接调用软中断”?试想一下下半部引入的理念，就是为了让上半部更快地执行。 如果在中断程序代码中直接调用软中断函数，那么就失去了上半部与下半部的区别，也就是失去了其存在的意义。</p>
</blockquote>
<p>我们来看一下这个 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L422">raise_softirq_irqoff()</a> 函数：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">inline</span> <span class="type">void</span> <span class="title function_">raise_softirq_irqoff</span><span class="params">(<span class="type">unsigned</span> <span class="type">int</span> nr)</span></span><br><span class="line">&#123;</span><br><span class="line">	__raise_softirq_irqoff(nr); <span class="comment">//置位图，即标记为可执行状态</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * If we&#x27;re in an interrupt or softirq, we&#x27;re done</span></span><br><span class="line"><span class="comment">	 * (this also catches softirq-disabled code). We will</span></span><br><span class="line"><span class="comment">	 * actually run the softirq once we return from</span></span><br><span class="line"><span class="comment">	 * the irq or softirq.</span></span><br><span class="line"><span class="comment">	 *</span></span><br><span class="line"><span class="comment">	 * Otherwise we wake up ksoftirqd to make sure we</span></span><br><span class="line"><span class="comment">	 * schedule the softirq soon.</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">    <span class="comment">// 设置了位图后，可以判断是否已经没有在中断上下文中了，如果没有，则是一个立即调用软中断的好时机。</span></span><br><span class="line">	<span class="keyword">if</span> (!in_interrupt())   <span class="comment">// in_interrupt另一个作用是判断软中断是否被禁用。</span></span><br><span class="line">		wakeup_softirqd(); <span class="comment">// wakeup_softirqd唤醒软中断的守护进程ksoftirq。</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>（1）最重要的，就是置相应的位图，等待将来被处理；</p>
<p>（2）如果此时已经没有在中断上下文中，则立即调用(其实是内核线程的唤醒操作)，现在就是将来；</p>
<h2 id="3-软中断的初始化"><a href="#3-软中断的初始化" class="headerlink" title="3. 软中断的初始化"></a><font size=3>3. 软中断的初始化</font></h2><p>软中断必须在编译的时候静态注册！ Linux 内核使用 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L625">softirq_init()</a> 函数初始化软中断：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> __init <span class="title function_">softirq_init</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> cpu;</span><br><span class="line"></span><br><span class="line">	for_each_possible_cpu(cpu) &#123;</span><br><span class="line">		per_cpu(tasklet_vec, cpu).tail =</span><br><span class="line">			&amp;per_cpu(tasklet_vec, cpu).head;</span><br><span class="line">		per_cpu(tasklet_hi_vec, cpu).tail =</span><br><span class="line">			&amp;per_cpu(tasklet_hi_vec, cpu).head;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	open_softirq(TASKLET_SOFTIRQ, tasklet_action);</span><br><span class="line">	open_softirq(HI_SOFTIRQ, tasklet_hi_action);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L625">softirq_init()</a>函数默认会打开 TASKLET_SOFTIRQ 和HI_SOFTIRQ。这个部分在linux初始化的时候就做好了，我们不用再去初始化一遍了。</p>
<h1 id="三、中断的下半部"><a href="#三、中断的下半部" class="headerlink" title="三、中断的下半部"></a><font size=3>三、中断的下半部</font></h1><p>前面我们知道，一开始 Linux 内核提供了“bottom half”机制来实现下半部，简称“BH”。后面引入了软中断和 tasklet 来替代“BH”机制，完全可以使用软中断和 tasklet 来替代 BH，从 2.5 版本的 Linux内核开始 BH 已经被抛弃了。其实tasklet 也是一种软中断，下面简单了解下软中断完成下半部的流程吧。</p>
<h2 id="1-软中断怎么完成中断下半部？"><a href="#1-软中断怎么完成中断下半部？" class="headerlink" title="1. 软中断怎么完成中断下半部？"></a><font size=3>1. 软中断怎么完成中断下半部？</font></h2><p>中断的上下半部处理流程如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250318155714988.png" alt="image-20250318155714988"  />

<p>画成流程图就是：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/1.iodraw.png"  />

<p>假设硬件中断A的上半部函数为 irq_top_half_A ，下半部为irq_bottom_half_A。  </p>
<ul>
<li>硬件中断 A 处理过程中，没有其他中断发生：</li>
</ul>
<p>（1）一开始， preempt_count &#x3D; 0；  </p>
<p>（2）上述流程图①～⑨依次执行，上半部、下半部的代码各执行一次。  </p>
<ul>
<li>硬件中断 A 处理过程中，又再次发生了中断 A</li>
</ul>
<p>（1）一开始， preempt_count &#x3D; 0；  </p>
<p>（2）执行到第⑥时，一开中断后，中断 A 又再次使得 CPU 跳到中断向量表。注意：这时 preempt_count 等于 1，并且中断下半部的代码并未执行。    </p>
<p>（3）CPU 又从①开始再次执行中断 A 的上半部代码：  </p>
<p>（4）在第①步 preempt_count 等于 2；  </p>
<p>（5）在第③步 preempt_count 等于 1；  </p>
<p>（6）在第④步发现 preempt_count 等于 1，所以直接结束当前第 2 次中断的处理  </p>
<p>注意：第 2 次中断发生后，打断了第一次中断的第⑦步处理。当第 2次中断处理完毕， CPU 会继续去执行第⑦步。  可以看到，发生 2 次硬件中断 A 时，它的上半部代码执行了 2 次，但是<strong>下半部代码只执行了一次</strong>。</p>
<p>所以，<strong>同一个中断的上半部、下半部，在执行时是多对一的关系</strong>。  </p>
<ul>
<li>硬件中断 A 处理过程中，又再次发生了中断 B</li>
</ul>
<p>（1）一开始， preempt_count &#x3D; 0；  </p>
<p>（2）执行到第⑥时，一开中断后，中断 B 又再次使得 CPU 跳到中断向量表。注意：这时 preempt_count 等于 1，并且中断 A 下半部的代码并未执行。  </p>
<p>（3）CPU 又从①开始再次执行中断 B 的上半部代码：  </p>
<p>（4）在第①步 preempt_count 等于 2；  </p>
<p>（5）在第③步 preempt_count 等于 1；</p>
<p>（6）在第④步发现 preempt_count 等于 1，所以直接结束当前第 2 次中断的处理</p>
<p>注意：第 2 次中断发生后，打断了第一次中断 A 的第⑦步处理。当第2 次中断 B 处理完毕， CPU 会继续去执行第⑦步。在第⑦步里，它会去执行中断 A 的下半部，也会去执行中断 B 的下半部。 </p>
<p>所以，<strong>多个中断的下半部，是汇集在一起处理的。</strong>     </p>
<blockquote>
<p>总结</p>
<p>（1）中断的处理可以分为上半部，下半部  </p>
<p>（2）中断上半部，用来处理紧急的事，它是在关中断的状态下执行的  </p>
<p>（3）中断下半部，用来处理耗时的、不那么紧急的事，它是在开中断的状态下执行</p>
<p>（4）中断下半部执行时，有可能会被多次打断，有可能会再次发生同一个中断  </p>
<p>（5）中断上半部执行完后，触发中断下半部的处理  </p>
<p>（6）中断上半部、下半部的执行过程中，不能休眠。（中断休眠的话，以后谁来调度进程？）</p>
</blockquote>
<h1 id="四、软中断demo"><a href="#四、软中断demo" class="headerlink" title="四、软中断demo"></a><font size=3>四、软中断demo</font></h1><h2 id="1-demo源码"><a href="#1-demo源码" class="headerlink" title="1. demo源码"></a><font size=3>1. demo源码</font></h2><h3 id="1-1-linux内核源码修改"><a href="#1-1-linux内核源码修改" class="headerlink" title="1.1 linux内核源码修改"></a><font size=3>1.1 linux内核源码修改</font></h3><p>这个我们要添加一个自定义软中断，我们打开 <a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/include/linux/interrupt.h#L477">interrupt.h - include&#x2F;linux&#x2F;interrupt.h</a>，找到软中断请求描述符的枚举，并添加我们自己的软中断号：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323110944722.png" alt="image-20250323110944722" />

<p>还有一个地方也要改一下，如下图编译驱动的时候会有警告，open_softirq 和 raise_softirq 没有被定义， 但是为什么还会提示这样的错误呢？这是因为 Linux 内核开发者不希望驱动工程师擅自在枚举类型中添加软中断。 </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323113247086.png" alt="image-20250323113247086" />

<p>我们需要将这两个函数导出到符号表：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L454">open_softirq()</a></li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">open_softirq</span><span class="params">(<span class="type">int</span> nr, <span class="type">void</span> (*action)(<span class="keyword">struct</span> softirq_action *))</span></span><br><span class="line">&#123;</span><br><span class="line">	softirq_vec[nr].action = action;</span><br><span class="line">&#125;</span><br><span class="line">EXPORT_SYMBOL(open_softirq);</span><br></pre></td></tr></table></figure>

<ul>
<li><a target="_blank" rel="noopener" href="https://elixir.bootlin.com/linux/v4.19.71/source/kernel/softirq.c#L439">raise_softirq()</a></li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">raise_softirq</span><span class="params">(<span class="type">unsigned</span> <span class="type">int</span> nr)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">unsigned</span> <span class="type">long</span> flags;</span><br><span class="line"></span><br><span class="line">	local_irq_save(flags);</span><br><span class="line">	raise_softirq_irqoff(nr);</span><br><span class="line">	local_irq_restore(flags);</span><br><span class="line">&#125;</span><br><span class="line">EXPORT_SYMBOL(raise_softirq);</span><br></pre></td></tr></table></figure>

<p>然后重新编译镜像：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">编译自己移植的开发板镜像</span></span><br><span class="line">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- clean</span><br><span class="line">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_alpha_emmc_defconfig</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j16 <span class="comment"># 全编译</span></span></span><br><span class="line">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage -j16 # 只编译内核镜像</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs -j16   <span class="comment"># 只编译所有的设备树</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx6ull-alpha-emmc.dtb -j16 <span class="comment"># 只编译指定的设备树</span></span></span><br><span class="line"></span><br><span class="line">cp -avf arch/arm/boot/zImage ~/3tftp</span><br></pre></td></tr></table></figure>

<h3 id="1-2-驱动源码"><a href="#1-2-驱动源码" class="headerlink" title="1.2 驱动源码"></a><font size=3>1.2 驱动源码</font></h3><p>然后驱动的源码我们可以看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-driver-demo/tree/master/13_interrupt/05_nodts_soft_irq">13_interrupt&#x2F;05_nodts_soft_irq · 苏木&#x2F;imx6ull-driver-demo - 码云 - 开源中国</a>。我们在按键中断中触发一个软中断。</p>
<h2 id="2-开发板测试"><a href="#2-开发板测试" class="headerlink" title="2. 开发板测试"></a><font size=3>2. 开发板测试</font></h2><p>我们更新内核，然后加载驱动：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">insmod sdriver_demo.ko</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323114255189.png" alt="image-20250323114255189" />

<p>然后我们按下按键，就会发现，按键的中断触发了，软中断也触发了：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/LV06-13-%E4%B8%AD%E6%96%AD-03-%E8%BD%AF%E4%B8%AD%E6%96%AD/img/image-20250323114328644.png" alt="image-20250323114328644" />

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/22e3d685.html">LV06-13-中断-03-软中断</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2025年03月23日 - 18:40</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/22e3d685.html" title="LV06-13-中断-03-软中断">https://sumumm.github.io/post/22e3d685.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV06-%E9%A9%B1%E5%8A%A8%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> LV06-驱动开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/765d0409.html" rel="prev" title="LV06-13-中断-03-中断下半部-01-tasklet">
                  <i class="fa fa-angle-left"></i> LV06-13-中断-03-中断下半部-01-tasklet
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/2cfac5ce.html" rel="next" title="LV06-12-ConfigFS-04-参考资料解析">
                  LV06-12-ConfigFS-04-参考资料解析 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
